﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BDCS.BLL;
using BDCS.Model;

namespace BDCS.UI
{
    public partial class AddBuildDesignDcriterionTypes : Form
    {
        #region 成员字段
        private BDCS.BLL.T_BuildDesignDcriterionTypes bllBuildDesignDcriterionTypes;
        private BDCS.Model.T_BuildDesignDcriterionTypes modelBuildDesignDcriterionTypes;
        private DataSet dataSet;
        #endregion
        #region 构造函数
        public AddBuildDesignDcriterionTypes()
        {
            InitializeComponent();
        }
        #endregion
        #region 成员事件
        private void btnOk_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(this.txtBuildDesignDcriterionTypeName.Text.Trim()))
            {
                MessageBox.Show("请输入规范大类名称！");
            }
            else
            {
                if (this.txtBuildDesignDcriterionTypeName.Text.Length >= 50)
                {
                    MessageBox.Show("输入内容长度大于50，请重新输入！");
                }
                else
                {
                    modelBuildDesignDcriterionTypes = new Model.T_BuildDesignDcriterionTypes();
                    modelBuildDesignDcriterionTypes.DTName = this.txtBuildDesignDcriterionTypeName.Text.Trim();
                    modelBuildDesignDcriterionTypes.DTDescirbe = this.txtBuildDesignDcriterionTypeDescribe.Text.Trim();
                    dataSet = new DataSet();
                    bllBuildDesignDcriterionTypes = new BLL.T_BuildDesignDcriterionTypes();
                    dataSet = bllBuildDesignDcriterionTypes.GetList("DTName=" + "'" + this.txtBuildDesignDcriterionTypeName.Text.Trim() + "'");
                    if (dataSet.Tables[0].Rows.Count == 0)
                    {
                        if (bllBuildDesignDcriterionTypes.Add(modelBuildDesignDcriterionTypes) != 0)
                        {
                            BDCS.Common.TreeViewState.IsChangedDcriterion = true;
                            MessageBox.Show("新增规范大类成功！");
                        }
                        else
                        {
                            MessageBox.Show("新增规范大类失败，请重新输入！");
                        }
                    }
                    else
                    {
                        MessageBox.Show("该规范大类名称已经存在，请重新输入！");
                    }
                }
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.txtBuildDesignDcriterionTypeName.Text = string.Empty;
            this.txtBuildDesignDcriterionTypeDescribe.Text = string.Empty;
        } 
        #endregion
    }
}
